﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConAppPrimeNumber
{

    class Program
    {
        static void Main(string[] args)
        {

            System.Diagnostics.Stopwatch s = new Stopwatch();

            s.Reset();
            s.Start();
            PrimeNumber.Find4();
            s.Stop();
            System.Console.WriteLine("Watch Time:{0}m, {1}s, {2}ms", s.Elapsed.Minutes, s.Elapsed.Seconds, s.ElapsedMilliseconds);

        }
    }


    public class PrimeNumber
    {
        static int n = 100000;         
        static bool IsPN = false;   //true
        static int count = 0;       //

        public static void Find()
        {
            for (int i = 1; i < n; i++)
            {
                if (i % 2 == 0) continue;
                System.Console.Write(i + "\t");
            }
        }

        public static void Find2()
        {
            for (int i = 1; i < n; i = i + 2)
            {
                System.Console.Write(i + "\t");
            }
        }

        public static void Find3()
        {
            IsPN = false;
            System.Console.Write(2 + "\t" + 3 + "\t");
            count = 2;

            for (int i = 1; i < n; i += 2)
            {
                for (int j = 3; j < i; j += 2)
                {
                    if (i % j == 0)
                    {
                        IsPN = false;
                        break;
                    }
                    IsPN = true;
                }
                if (IsPN)
                {
                    System.Console.Write(i + "\t");   
                    count++;
                }
            }
            System.Console.WriteLine("Count: {0}", count);
        }

        public static void Find4()
        {
            IsPN = false;
            System.Console.Write(2 + "\t" + 3 + "\t");
            count = 2;

            for (int i = 1; i < n; i += 2)
            {
                for (int j = 3; j < i; j += 2)
                {
                    if (i % j == 0)
                    {
                        IsPN = false;
                        break;
                    }

                    if (j * j > i)
                    {
                        IsPN = true;
                        break;
                    }
                }

                if (IsPN)
                {
                    System.Console.Write(i + "\t");  
                    count++;
                }
            }
            System.Console.WriteLine("Count: {0}", count);
            Console.ReadKey();
        }

    }
}